package com.example.demo.controller;

import com.example.demo.model.Administrator;
import com.example.demo.model.Leave;
import com.example.demo.model.User;
import com.example.demo.server.loingServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.security.Timestamp;

@Controller
public class LoingConteroller {
  @Autowired
 public loingServer loingServer;
    //前台注册
  @RequestMapping("/zhuce")
  public String add(User user){
      int add = loingServer.add(user);
      return "index1";
  }
    //前台登录
    @GetMapping("/denglu")
    public String selup(String uname,String password,Model model){
        System.out.println(uname);
        System.out.println(password);
        User seleup = loingServer.seleup(uname, password);
        System.out.println(seleup);
        //判断数据库里是否有账号密码
        if (seleup!=null){
            model.addAttribute("seleup",seleup);
            return"index";
        }
        model.addAttribute("op",0);
        return "index1";
    }
    //后台登录
    @RequestMapping("/denglu1")
    public String seleAd(String user,String password,Model model){
        System.out.println(user);
        System.out.println(password);
        Administrator admin = loingServer.seleAd(user,password);
        System.out.println(admin);
        if (admin!=null){
            model.addAttribute("admin1",admin);
            return "frame";
        }
        model.addAttribute("admin",0);
        return "login1";
    }
    //前台留言
    @RequestMapping("/liuyan")
    public String addLeave(Leave leave){
        int i = loingServer.addLeave(leave);
        System.out.println(i);
        return "index";
    }
}
